package com.zq.zqmanager.config;

import com.zq.zqmanager.job.MyJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: zqmanager
 * @Date: 2020/3/8 19:49
 * @Author: zhengqiang
 * @Description: 定义jobdetail，和trigger
 */
//@Configuration
public class QuartzConfiguration {

    //定义jobdetail
    @Bean
    public JobDetail myJobDetail(){
        return JobBuilder.newJob(MyJob.class).withIdentity("myjob").storeDurably()
                .usingJobData("key","world")
                .build();
    }

    @Bean
    public Trigger myTrigger(){
        //定义具体什么时间执行，定义一个每3秒执行的计划表
        SimpleScheduleBuilder builder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever();
        return TriggerBuilder.newTrigger().forJob(myJobDetail()).withIdentity("mytrigger").withSchedule(builder).build();
    }

}
